﻿using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Windows;
using System.Windows.Threading;

namespace MetaView.WPF
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        public new static App Current => (App)Application.Current;

        private async void Application_Startup(object sender, StartupEventArgs e)
        {
#if DEBUG
            //if (Debugger.IsAttached)
            //{
            //    Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName)
            //        .Where(p => p.Id != Environment.ProcessId)
            //        .ForEach(p =>
            //        {
            //            p.Kill();
            //            p.WaitForExit();
            //        });
            //}
#endif

            //var flags = new Flags(e.Args);

            //Log.Instance.IsTraceEnabled = flags.IsTraceEnabled;

            AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException;
        }

        private void Application_Exit(object sender, ExitEventArgs e)
        {
            //_singleInstanceMutex?.Close();
        }

        private void AppDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var exception = e.ExceptionObject as Exception;

            //MessageBox.Show(string.Format(Resource.UnexpectedException, exception?.ToStringDemystified() ?? "Unknown exception.", Constants.ProjectUri),
            //"Application Domain Error",
            //MessageBoxButton.OK,
            //MessageBoxImage.Error);
        }

        private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            
        }
    }
}
